package com.example.demo.mapper.sysfile;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.bean.PageRes;
import com.example.demo.bean.sysfile.SysFileDO;
import com.example.demo.mapper.BaseMapperX;
import com.example.demo.dto.sysfile.SysFilePageReqVO;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface SysFileMapper extends BaseMapperX<SysFileDO> {
    default PageRes<SysFileDO> selectPage(SysFilePageReqVO reqVO) {
        Page<SysFileDO> page = new Page<>(reqVO.getPageNo(), reqVO.getPageSize());
        return selectPageCommon(page, new QueryWrapper<SysFileDO>()
                .like(ObjectUtil.isNotNull(reqVO.getName()), "name", reqVO.getName())
                .eq(ObjectUtil.isNotNull(reqVO.getType()), "type", reqVO.getType())
                .eq(ObjectUtil.isNotNull(reqVO.getSource()), "source", reqVO.getSource())
                .eq(ObjectUtil.isNotNull(reqVO.getCid()), "cid", reqVO.getCid())
                .between(
                        ObjectUtil.isNotNull(reqVO.getTimeArr()),
                        "create_time",
                        ArrayUtil.get(reqVO.getTimeArr(), 0),
                        ArrayUtil.get(reqVO.getTimeArr(), 1)
                )
        );
    }

    default PageRes<SysFileDO> selectNotPage(SysFilePageReqVO reqVO) {
        return selectPageCommon(new QueryWrapper<SysFileDO>()
                .like(ObjectUtil.isNotNull(reqVO.getName()), "name", reqVO.getName())
                .eq(ObjectUtil.isNotNull(reqVO.getType()), "type", reqVO.getType())
                .eq(ObjectUtil.isNotNull(reqVO.getSource()), "source", reqVO.getSource())
                .eq(ObjectUtil.isNotNull(reqVO.getCid()), "cid", reqVO.getCid())
                .between(
                        ObjectUtil.isNotNull(reqVO.getTimeArr()),
                        "create_time",
                        ArrayUtil.get(reqVO.getTimeArr(), 0),
                        ArrayUtil.get(reqVO.getTimeArr(), 1)
                )
        );
    }
}
